<?php
namespace app\index\model;

use think\Model;
use traits\model\SoftDelete;
class AuthGroup extends Model{
    Use SoftDelete;
    protected $deleteTime="del_time";
    protected function getStatusAttr($value){
        $status=\think\Config::get('status');
        return $status[$value];
    }



    public static function grouplist($data=[],$query=[],$page=true){
        $model=self::field(true);
        if(!empty($data['title'])) $model->where('title','like','%'.$data['title'].'%');

        if($page){
            $request=$model->paginate(2,false,['query' => $query]);
        }else{
            $request=$model->select();
        }
        $list=$request;

        return $list;
    }

    public function edit_group($data=[]){
        try{
            if(empty($data)){
                $this->error="不能为空";
                return false;
            }
            if($data)
                return $this->isUpdate(true)->allowField(true)->save($data);

        }catch(\Exception $e){
            $this->error=$e->getMessage();
            return false;
        }


    }

    public static function huishouGroup($data=[],$query=[],$page=true){
        $model=self::onlyTrashed();
        if(!empty($data['title'])) $model->where('title','like','%'.$data['title'].'%');

        if($page){
            $request=$model->paginate(1,false,['query' => $query]);
        }else{
            $request=$model->select();
        }
        $list=$request;

        return $list;
    }

    public function addlist($data=[]){
        try {
            if (empty($data)) {
                $this->error = "不能为空";
                return false;
            }
            $rt= $this->allowField(true)->save($data);
            return $rt;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            return false;
        }
    }





}